home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / ODFDev / Button / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-12-16  |  6.0 KB  |  225 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.cpp
  4. //    Release Version:    $ ODF 3 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef CONTENT_H
  13. #include "Content.h"
  14. #endif
  15.  
  16. #ifndef PART_H
  17. #include "Part.h"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef DEFINES_K
  25. #include "Defines.k"
  26. #endif
  27.  
  28. #ifndef ACTIONS_H
  29. #include "Actions.h"
  30. #endif
  31.  
  32. #ifndef FWKIND_H
  33. #include "FWKind.h"
  34. #endif
  35.  
  36. #ifndef FWSUSINK_H
  37. #include "FWSUSink.h"
  38. #endif
  39.  
  40. #ifndef FWSUUTIL_H
  41. #include "FWSUUtil.h"
  42. #endif
  43.  
  44. #ifndef FWAROPER_H
  45. #include "FWArOper.h"
  46. #endif
  47.  
  48. #ifndef FWNOTIFI_H
  49. #include "FWNotifi.h"
  50. #endif
  51.  
  52. #ifndef SOM_ODStorageUnit_xh
  53. #include <StorageU.xh>
  54. #endif
  55.  
  56. //========================================================================================
  57. //    Runtime information
  58. //========================================================================================
  59.  
  60. #ifdef FW_BUILD_MAC
  61. #pragma segment odfbutton
  62. #endif
  63.  
  64. //========================================================================================
  65. //    Class CButtonContent
  66. //========================================================================================
  67.  
  68. FW_DEFINE_AUTO(CButtonContent)
  69.  
  70. //----------------------------------------------------------------------------------------
  71. // CButtonContent constructor
  72. //----------------------------------------------------------------------------------------
  73.  
  74. CButtonContent::CButtonContent(Environment* ev, CButtonPart* part) :
  75.     FW_CContent(ev, part),
  76.     fAction(NULL),
  77.     fPart(part),
  78.     fActionType(0)
  79. {
  80.     FW_END_CONSTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. // CButtonContent destructor
  85. //----------------------------------------------------------------------------------------
  86.  
  87. CButtonContent::~CButtonContent()
  88. {
  89.     FW_START_DESTRUCTOR
  90.     delete fAction;
  91. }
  92.  
  93. //----------------------------------------------------------------------------------------
  94. // CButtonContent::ExternalizeKind
  95. //----------------------------------------------------------------------------------------
  96.  
  97. void CButtonContent::ExternalizeKind(Environment* ev,
  98.                                  ODStorageUnit* destinationSU,
  99.                                  FW_CKind* kind,
  100.                                  FW_StorageKinds storageKind,
  101.                                  FW_CPromise* promise,
  102.                                  FW_CCloneInfo* cloneInfo)
  103. {
  104. FW_UNUSED(promise);
  105. FW_UNUSED(storageKind);
  106. FW_UNUSED(cloneInfo);
  107.     if (kind->IsPartKind(ev))
  108.     {
  109.         FW_PStorageUnitSink sink(ev, destinationSU, kODPropContents, kind->GetType(ev));
  110.         FW_CWritableStream stream(sink);
  111.         stream << fActionType;
  112.         FW_SUDeleteEndOfFocusedValue(ev, destinationSU);
  113.     }
  114.     else if (kind->IsEqual(ev, fPart->fDataSoundKind))
  115.     {
  116.         FW_ASSERT(fAction != NULL);
  117.         FW_ASSERT(fAction->GetActionType() == kSound);
  118.         fAction->Externalize(ev, destinationSU, kind);
  119.     }
  120.     else if (kind->IsEqual(ev, fPart->fDataScriptKind))
  121.     {
  122.         FW_ASSERT(fAction != NULL);
  123.         FW_ASSERT(fAction->GetActionType() == kScript);
  124.         fAction->Externalize(ev, destinationSU, kind);
  125.     }
  126.         
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. // CButtonContent::InternalizeKind
  131. //----------------------------------------------------------------------------------------
  132.  
  133. FW_Boolean CButtonContent::InternalizeKind(Environment* ev,
  134.                                     ODStorageUnit* storage, 
  135.                                      FW_CKind* kind,
  136.                                     FW_StorageKinds storageKind,
  137.                                     FW_CCloneInfo* cloneInfo)
  138. {
  139. FW_UNUSED(storageKind);
  140. FW_UNUSED(cloneInfo);
  141.     
  142.     CAction* action = NULL;
  143.     short actionType = kNothing;
  144.     
  145.     if (kind->IsPartKind(ev))
  146.     {
  147.         FW_PStorageUnitSink sink(ev, storage, kODPropContents, kind->GetType(ev));
  148.         FW_CReadableStream stream(sink);
  149.         stream >> actionType;
  150.         
  151.         if (actionType == kSound)
  152.         {
  153.             if (storage->Exists(ev, kODPropContents, fPart->fDataSoundKind->GetType(ev), 0))
  154.                 action = new CSoundAction(ev, storage, fPart->fDataSoundKind);
  155.         }
  156.         else if (actionType == kScript)
  157.         {
  158.             if (storage->Exists(ev, kODPropContents, fPart->fDataScriptKind->GetType(ev), 0))
  159.                 action = new CScriptAction(ev, storage, fPart->fDataScriptKind);
  160.         }
  161.     }
  162.     else if (kind->IsEqual(ev, 'snd ', kODPlatformDataType) || kind->IsEqual(ev, 'sfil', kODPlatformFileType))
  163.     {
  164.         action = new CSoundAction(ev, storage, kind);
  165.         actionType = kSound;
  166.     }
  167.     else if (kind->IsEqual(ev, 'scpt', kODPlatformDataType) || kind->IsEqual(ev, 'osas', kODPlatformFileType))
  168.     {
  169.         action = new CScriptAction(ev, storage, kind);
  170.         actionType = kScript;
  171.     }
  172.     else
  173.         FW_DEBUG_MESSAGE("CButtonContent::InternalizeKind - Unknown type");
  174.     
  175.     ChangeAction(ev, action, actionType);
  176.  
  177.     return true;
  178. }
  179.  
  180.         
  181. //----------------------------------------------------------------------------------------
  182. //    CButtonContent::ChangeAction
  183. //----------------------------------------------------------------------------------------
  184.  
  185. void CButtonContent::ChangeAction(Environment* ev, CAction* action, short actionType)
  186. {
  187.     if (action != fAction)
  188.     {
  189.         if (actionType != fActionType)
  190.         {
  191.             if (fActionType == kSound)
  192.                 fPart->fDataSoundKind->ChangeImportExport(ev, FW_kImport);
  193.             else if (fActionType == kScript)
  194.                 fPart->fDataScriptKind->ChangeImportExport(ev, FW_kImport);
  195.             
  196.             fActionType = actionType;
  197.             
  198.             if (fActionType == kSound)
  199.                 fPart->fDataSoundKind->ChangeImportExport(ev, FW_kImportExportEnabled);
  200.             else if (fActionType == kScript)
  201.                 fPart->fDataScriptKind->ChangeImportExport(ev, FW_kImportExportEnabled);
  202.         }
  203.         
  204.         delete fAction;
  205.         fAction = action;
  206.     }
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    CButtonContent::HandleNotification
  211. //----------------------------------------------------------------------------------------
  212.  
  213. void CButtonContent::HandleNotification(Environment* ev, const FW_CNotification& notification)
  214. {
  215. FW_UNUSED(ev);
  216.  
  217.     if (notification.GetMessage() == FW_kButtonPressedMsg && fAction != NULL)
  218.     {
  219.         // no need to check for the button ID, there is only 1 button in this frame
  220.         fAction->DoIt();        
  221.     }
  222. }
  223.  
  224.  
  225.